<?php

include('../../includes/classes/core.php');

$action 	= $_REQUEST['act'];
$error		= '';
$data		= '';

switch ($action) {
	case 'get_list' :
		$count      = $_REQUEST['count'];
		$hidden     = $_REQUEST['hidden'];
		$start		= $_REQUEST['start'];
		$end		= $_REQUEST['end'];
	  	$rResult = mysql_query("SELECT 	datetime,
                                        datetime,
                                        source,
                                        CONCAT(dst_queue,' - ', dst_extension),
                                        SEC_TO_TIME(duration) as `time`,
                                        CONCAT('<p onclick=play(', '\'',file_name, '\'',  ')>მოსმენა</p>', '<a download=\"',file_name,'\" href=\"http://212.72.155.175:8181/records/', file_name,'\">ჩამოტვირთვა</a>')
                                FROM 	asterisk_incomming
                                WHERE 	disconnect_cause != 'ABANDON'
                                AND 	DATE(datetime) >= '$start'
                                AND 	DATE(datetime) <= '$end'");
									  	
		$data = array(
				"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count ; $i++ )
			{
				/* General output */
				$row[] = $aRow[$i];
			}
			$data['aaData'][] = $row;
		}

		break;
		
	default:
		$error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

?>